package net.lunjin.service.impl;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import net.lunjin.bean.Organizations;
import net.lunjin.bean.People;
import net.lunjin.dao.OrganizationsDao;
import net.lunjin.dao.PeopleDao;
import net.lunjin.service.PeopleService;
import net.lunjin.util.ProjectUtil;

import org.springframework.beans.factory.annotation.Autowired;

import finaler.util.DateUtil;
import finaler.util.Page;
import finaler.util.PageList;

public class PeopleServiceImpl implements PeopleService {

	@Autowired
	private PeopleDao peopleDao;

	@Autowired
	private OrganizationsDao organizationsDao;

	@Override
	public int getCount(int typeflag) throws Exception {
		return peopleDao.getCount(typeflag);
	}

	@Override
	public List<People> getTop5WantPeople(BigDecimal orgId) throws Exception {
		return peopleDao.getTop5WantPeople(orgId);
	}
	
	@Override
	public List<Map<String, Object>> getTop5Proxy() throws Exception {
		return peopleDao.getTop5Proxy();
	}

	@Override
	public void insert(People people) throws Exception {
		peopleDao.insert(people);
	}

	@Override
	public People findPeople(BigDecimal orgId, String telipqq, String typeflag) throws Exception {
		return peopleDao.findPeople(orgId, telipqq, typeflag);
	}

	@Override
	public List<People> getAllProxy(BigDecimal orgId) throws Exception {
		return peopleDao.getAllProxy(orgId);
	}

	@Override
	public int getCountWantPeople(BigDecimal orgId) throws Exception {
		return peopleDao.getCountWantPeople(orgId);
	}

	@Override
	public PageList getWantPeople(Page page) throws Exception {
		return peopleDao.getWantPeople(page);
	}

	//自动每1小时增加一个入户数
	@Override
	public void randomWant() throws Exception {
		Organizations organizations = organizationsDao.getRandomRecord();//随机获得一个交易平台
		if(organizations==null){return;}
		People people = new People();
		people.setCreatetime(DateUtil.getCurrentDate("yyyy-MM-dd"));
		people.setOrgid(organizations.getId());
		people.setTypeflag(new BigDecimal(0));
		people.setAutoFlag(new BigDecimal(1));
		people.setTelipqq(ProjectUtil.getRandomIP());
		peopleDao.insert(people);
	}

	@Override
	public void deleteByOrgid(BigDecimal orgId) throws Exception {
		peopleDao.deleteByOrgid(orgId);
	}

	@Override
	public void deleteLowComWant() throws Exception {
		peopleDao.deleteLowComWant();
		
	}
}
